<assign name="page_title" value="$school.school_name" />
<include file="Public:header" />
<div id="main">
    <div id="main-header" class="grid page">
        <h2>正在发生什么..</h2>
        <h1>{{$school.school_name}}</h1>
    </div>
    <div id="sub-main-header"></div>
    <div class="page dash grid" id="share-content">
        <ul class="lite_inline clearfix" id="share-selectors">
            <li class="share_button selected">
                <a class="share_button share_love" href="javascript:" autofocus="true">{{$Think.config.TWEETS_CATEGORY.1}}</a><i class="nub"></i>
            </li>
            <li class="share_button ">
                <a class="share_button share_choose" href="javascript:" autofocus="true">{{$Think.config.TWEETS_CATEGORY.2}}</a><i class="nub hidden" ></i>
            </li>
            <li class="share_button ">
                <a class="share_button share_secret" href="javascript:" autofocus="true">{{$Think.config.TWEETS_CATEGORY.3}}</a><i class="nub hidden" ></i>
            </li>
        </ul>
        <div class="share">
            <form action="__ROOT__/api/tweets/save" method="post" id="share-love-form" class="share_form">
                <input type="hidden" value="{{$school.school_id}}" name="school_id" />
                <input type="hidden" value="1" name="cate_id" />
                <input type="hidden" value="male" name="sex" />
                <textarea placeholder="爱要大声喊出来..." class="textarea" name="content" style="width:100%;"></textarea>
                <!--<a id="share-location-text" class="left btn btn_lblue share_location" href="javascript:"><span><b></b>标记发生地点<i></i></span></a>-->
                <button type="button" name="_sex" value="male" class="submit_tweets btn btn_silver right fbold"><span>Ta是男生</span></button>
                <button type="button" name="_sex" value="female" class="submit_tweets btn btn_silver right fbold"><span>Ta是女生</span></button>
            </form>
            <!--显示地址
            <form action="__ROOT__/Home/index/locationShow" method="post">
                <input type="text" name="location" value="" />
                <button type="submit">搜索</button>
            </form>-->
        </div>
        <div class="share hidden">
            <form action="__ROOT__/api/tweets/save" method="post" id="share-choose-form" class="share_form">
                <input type="hidden" value="{{$school.school_id}}" name="school_id" />
                <input type="hidden" value="2" name="cate_id" />
                <textarea placeholder="我要怎么办啊..." class="textarea" name="content" style="width:100%;"></textarea>
                <button type="submit" class="submit_tweets btn btn_silver right fbold"><span>发不发呢？</span></button>
            </form>
        </div>
        <div class="share hidden">
            <form action="__ROOT__/api/tweets/save" method="post" id="share-secret-form" class="share_form">
                <input type="hidden" value="{{$school.school_id}}" name="school_id" />
                <input type="hidden" value="3" name="cate_id" />
                <textarea placeholder="我有一个小秘密..." class="textarea" name="content" style="width:100%;"></textarea>
                <!--<a id="share-location-text" class="left btn btn_lblue share_location" href="javascript:"><span><b></b>标记发生地点<i></i></span></a>-->
                <button type="submit" class="submit_tweets btn btn_silver right fbold"><span>说出来好了</span></button>
            </form>
        </div>
    </div>
    <div class="posts" id="posts">
    </div>
    <div id="more-wrapper">
        <div class="page" id="more-button-container">
            <a class="input_full btn btn_lblue btn_medium" href="javascript:" id="more-link"><span>加载更多主题..</span></a>
        </div>
    </div>
</div>
<include file="Public:_tpl_tweets" />
<script>
    Do(function(){
        $("#share-content .share .textarea").focus(function(){
            $("#share-selectors .nub:visible").addClass("focus");
        }).blur(function(){
            $("#share-selectors .nub:visible").removeClass("focus");
        });
        //主题类型切换
        $("#share-selectors>.share_button").click(function(e){
            if($(this).has(".nub:visible").length) return;
            var index = $(this).index();
            $(this).addClass("selected").siblings().removeClass("selected");
            $("#share-selectors .nub:visible").fadeOut("fast", function(){
                $(e.currentTarget).find(".nub").fadeIn("fast");
            });
            $("#share-content>.share:visible").fadeOut("fast", function(){
                $("#share-content>.share").eq(index).fadeIn("fast");
            });
            e.stopPropagation();
        });
    });
    Do("AGL.tweets",function(){
        //喜爱 - 性别设置
        $("button[name=_sex]","#share-love-form").click(function(){
            $("input[name=sex]","#share-love-form").val(this.value);
            $("#share-love-form").submit();
        });
        //发主题
        $(".share_form").submit(function(){
            var _self = this;
            var _textarea = $("textarea[name=content]",this);
            if(Cute.form.isInputNull(_textarea)){
                AGL.common.errorAnimation(_textarea);
                return false;
            }
            Cute.api.post("tweets/save",$(this).serialize(), function(json){
                if(json.status > 0){
                    $("textarea[name=content]", _self).val("");
                    $(Cute.template("NEW_TWEETS",json.data)).prependTo("#posts").hide().slideDown();
                }else{
                    new Cute.ui.dialog().alert(json.info);
                }
            });
            return false;   
        });
        //加载主题
        var loadTweets = function(options){
            AGL.tweets.list($.extend({
                element:"#posts",
                cate_id: {{$Think.get.cate_id|default=0}},
                    school_id:AGL.school.info.id,
                    climit:2,
                    limit:20,
                    callback: function(json){
                        $("#more-link").toggle(json.data && json.data.length >= this.limit);
                        if(json.data && json.data.length > 0){
                            $(this.element).data("start", json.data[json.data.length - 1].tweets_id);
                        }
                    }
                },options || {}));
            };
            loadTweets();
            $("#more-link").click(function(){
                loadTweets({
                    start:$("#posts").data("start")
                });
            });
//            $("#change-sex").hover(function(e){
//                this.timer = setTimeout(function(){
//                    $(this).css({
//                        "overflow":"visible",
//                        "height":"auto"
//                    });
//                }.bind(this),200);
//            },function(e){
//                clearTimeout(this.timer);
//                $(this).css({
//                    "overflow":"hidden",
//                    "height":"34px"
//                });
//            }).children("a").click(function(e){
//                if($(this).index() == 0) return false;
//                $(this).parent().trigger("mouseleave");
//                $(this).parent().prepend($(this));
//                $("#share-love-form input[name=sex]").val(this.className.indexOf("famale") != -1 ? "famale" : "male");
//                $("#share-love-form textarea[name=content]").focus();
//                e.stopPropagation();
//                e.preventDefault();
//                return false;
//            });
        });
</script>
<include file="Public:footer" />